package alejandro.castro.visual;

import java.awt.Color;
import java.awt.Graphics2D;

import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Appearance;

public class BlockAppearance implements Appearance {
	
	private int width = 100;
	private int height = 30;
	private int bgHeight;
	private int bgWidth;
	private Color borderColor;
	private Color bgColor;
	private int wbgMargin;
	private int hbgMargin;

	public BlockAppearance(int width, int height, Color borderColor, Color bgColor) {
		this.height = height;
		this.width = width;
		this.bgHeight = (int) Math.floor(height* 0.95);
		this.bgWidth = (int) Math.floor(width* 0.95);
		this.wbgMargin = (width - bgWidth) / 2;
		this.hbgMargin = (height - bgHeight) / 2;
		this.borderColor = borderColor;
		this.bgColor = bgColor;
	}

	@Override
	public double getWidth() {
		return width;
	}

	@Override
	public double getHeight() {
		return height;
	}

	@Override
	@SuppressWarnings("unchecked")
	public BlockAppearance copy() {
		return new BlockAppearance(width, height, borderColor, bgColor);
	}

	@Override
	public void update(double delta) {
		// Nothing here
	}

	@Override
	public void render(GameComponent<?> component, Graphics2D graphics) {
		graphics.setColor(borderColor);
		graphics.fillRect((int) component.getX(), (int) component.getY(), this.width, this.height);
		graphics.setColor(bgColor);
		graphics.fillRect((int) component.getX() + wbgMargin, (int) component.getY() + hbgMargin, this.bgWidth, this.bgHeight);
	}

}
